﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows.Forms;
using Butcher.winform.EnterpriseForms.MessSalguhterPut;
using Newtonsoft.Json.Linq;
using Sunny.UI.Win32;
using Traceability.Commont.Domains.BatchManagementFiles;
using static Butcher.winform.EnterpriseForms.MassSlaughter;

namespace Butcher.winform.EnterpriseForms
{
    public partial class MassSlaughter : Form
    {
        public MassSlaughter()
        {
            InitializeComponent();
            var i = 0;

            Gethtml();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SelectionOfBatch form2 = new SelectionOfBatch();
            form2.ShowDialog();

        }

        private void MassSlaughter_Load(object sender, EventArgs e)
        {

        }
        List<int> NewList = new List<int>();
        List<BulkSlaughter> list = new List<BulkSlaughter>();
        BulkSlaughter bulks = new BulkSlaughter();
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

            DataGridViewRow row = dataGridView1.Rows[e.RowIndex];
            var k = Convert.ToInt32(row.Cells["序号"].Value);
            NewList.Add(k);
            bulks.DocumentsTime = DateTime.Now;
            bulks.AccountingUnit = comboBox2.Text;
            bulks.DocumentsNo = textBox1.Text;
            bulks.ProductionCrews = comboBox1.Text;
            bulks.DateOfManufacture = Convert.ToDateTime(dateTimePicker2.Text);
            bulks.MakeASingle = "李斯";
            bulks.Reviewers = "李斯";
            bulks.LiveAnimalweighingId = Convert.ToInt32(row.Cells["序号"].Value);
            bulks.GoSlaughterType = Convert.ToString(row.Cells["送宰类型"].Value);
            bulks.SlaughterType = Convert.ToString(row.Cells["屠宰类型"].Value);
            bulks.BulkSlaughterNo = "123";
            bulks.BulkSlaughterNum = Convert.ToInt32(row.Cells["计划屠宰头数"].Value);
            bulks.BulkSlaughterTime = Convert.ToDateTime(row.Cells["计划屠宰日期"].Value);
            bulks.SlaughterTime = Convert.ToDecimal(row.Cells["计划屠宰时间"].Value);
            bulks.RecuperationTime = 3;
            bulks.Rremark = Convert.ToString(row.Cells["备注"].Value);
            bulks.CreateThisTime = DateTime.Now;
            bulks.UpdateThisTime = DateTime.Now;
            list.Add(bulks);
            //var k1 =row.Cells["屠宰顺序"].Value;
            //var k2 =row.Cells["进场编号"].Value;
            //var k3 =row.Cells["进场批次"].Value;
            //var k4 =row.Cells["供货商"].Value;
            //var k5 =row.Cells["送宰类型"].Value;
            //var k6 =row.Cells["屠宰编号"].Value;
            //var k7 =row.Cells["商品代号"].Value;
            //var k8 =row.Cells["计划屠宰头数"].Value;
            //var k9 =row.Cells["计划屠宰日期"].Value;
            //var k11 = row.Cells["计划屠宰时间"].Value;
            //var k12 = row.Cells["代宰圈号"].Value;
            //var k13 =row.Cells["备注"].Value;
        }


        public void Gethtml()
        {
            var url = @"http://localhost:5229/api/Batch/SlaughterCraeteList";

            HttpClient client = new HttpClient();
            NEWPUT nEWPUT = new NEWPUT();

            var content = new StringContent(JsonSerializer.Serialize<NEWPUT>(nEWPUT));
            content.Headers.Remove("Content-Type");
            content.Headers.Add("Content-Type", "application/json");
            string result = client.PostAsync(url, content).Result.Content.ReadAsStringAsync().Result;
            JObject info = JObject.Parse(result);
            var count = info["date"].Value<JArray>();
            dataGridView1.DataSource = count;




        }

        public class NEWPUT
        {
            public List<int> ids { get; set; }
        }
        public class createDTO
        {
            public List<BulkSlaughter> list { get; set; }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            createDTO dto = new createDTO();
            dto.list = list;
            var url = @"http://localhost:5229/api/Batch/BulkSlaughterCreate";
            HttpClient client = new HttpClient();
            var content = new StringContent(JsonSerializer.Serialize<createDTO>(dto));
            content.Headers.Remove("Content-Type");
            content.Headers.Add("Content-Type", "application/json");
            string result = client.PostAsync(url, content).Result.Content.ReadAsStringAsync().Result;
            JObject info = JObject.Parse(result);
            var count = info["code"].Value<int>();
            if (count > 0)
            {
                MessageBox.Show("添加成功");
            }
        }

    }
}
